package com.example.springbootcourse.controller;

import com.example.springbootcourse.pojo.Course;
import com.example.springbootcourse.pojo.Curelation;
import com.example.springbootcourse.req.CourseReq;
import com.example.springbootcourse.service.CourseService;
import com.example.springbootcourse.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
public class CourseController {

    @Autowired
    CourseService courseService;


    @GetMapping("/queryCourse")
    public Result queryCourse(){
        List<Course> courses = courseService.queryCourse();
        return Result.success(courses);
    }

    @PostMapping("/saveCourse")
    public Result saveUser(@RequestBody @Valid Course course){
        courseService.saveCourse(course);
        return Result.success();
    }

    @DeleteMapping("/delCourse/{id}")
    public Result delUser(@PathVariable  String id){
        courseService.delCourse(id);
        return Result.success();
    }

    @PostMapping("/arranging")
    public Result arranging(@RequestBody CourseReq req ){

        System.out.println(req);
        courseService.arranging(req);

        return Result.success();
    }

    @PostMapping("/listening")
    public Result listening(@RequestBody Curelation curelation ){

        courseService.listening(curelation);

        return Result.success();
    }

    @GetMapping("/queryCurelation")
    public Result queryCurelation(){
        List<Curelation> list =  courseService.queryCurelation();
        return Result.success(list);
    }

    // 删除听课安排
    @DeleteMapping("/delCurelation/{id}")
    public Result delCurelation(@PathVariable  String id){
        courseService.delCurelation(id);
        return Result.success();
    }











}
